package com.gdth.widget.textview;

import com.gdth.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

public class BaseTextView extends LinearLayout{
	protected Context context;
	
	/**
	 * label
	 */
	protected TextView txt_label;
	
	/**
	 * value
	 */
	protected TextView txt_value;
	
	protected int layout = R.layout.widget_textview;
	
	public BaseTextView(Context context, int layout) {
		super(context);
		
		this.context = context;
		this.layout = layout;
		
		init();
		initView();
	}
	
	public BaseTextView(Context context, AttributeSet attrs, int layout) {
		super(context, attrs);
		
		this.context = context;
		this.layout = layout;
		
		init();
		initView();
	}
	
	private void init() {
		LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(layout, this);
	}
	
	public void initView(){
        txt_label = (TextView) findViewById(R.id.widget_textview_label);
        txt_value = (TextView) findViewById(R.id.widget_textview_value);
	}
	
	public void setLabel(String label){
		txt_label.setText(label);
	}
	
	public void setLabel(int label){
		txt_label.setText(context.getResources().getString(label));
	}
	
	public String getValue(){
		return txt_value.getText().toString();
	}
	
	public void setValue(String value){
		txt_value.setText(value);
	}
	
	public void setCompoundDrawable(Drawable drawable){
		txt_value.setCompoundDrawables(null, null, drawable, null);
	}
	
	public void setOnClickListener(OnClickListener mOnClickListener){
		txt_value.setOnClickListener(mOnClickListener);
	}
}
